﻿<template>
  <div class="app-container">
    <div class="chart-title">档案管理</div>
    <div class="chart-content">
      <div class="filter-title">
        <el-form label-position="right">
          <el-form-item>
            <el-input
              v-model="listQuery.alias"
              style="width: 160px; height:32px;"
              class="filter-item"
              :placeholder="$t('terminal.alias')"
              @keyup.enter.native="handleFilter"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="listQuery.code"
              style="width: 160px; height:32px;"
              class="filter-item"
              :placeholder="$t('terminal.sn')"
              @keyup.enter.native="handleFilter"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="listQuery.name"
              style="width: 160px; height:32px;"
              class="filter-item"
              :placeholder="$t('terminal.name')"
              @keyup.enter.native="handleFilter"
            ></el-input>
          </el-form-item>
          <div
            class="search-button"
            @click="handleFilter"
          >
            <img src="@/assets/images/bg_search@2x.png" />
          </div>
          <div
            class="search-button"
            @click="handleRefresh"
          >
            <img src="@/assets/images/bg_reset@2x.png" />
          </div>
        </el-form>
        <div class="filter-right">
          <div
            class="add-button"
            @click="handleCreate"
          >
            <img src="@/assets/images/icon_add@2x.png" />
            <span>新建</span>
          </div>
        </div>
      </div>
      <div class="chart-list">
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          :data="list"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(255,255,255,0.2)"
          border
          fit
          highlight-current-row
          style="width: 100%min-height:1000px"
        >
          <el-table-column
            fixed="left"
            align="center"
            :label="$t('table.id')"
            width="65"
          >
            <template slot-scope="scope">
              <span>{{
                (listQuery.page - 1) * listQuery.limit + scope.$index + 1
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('terminal.alias')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.alias }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('terminal.sn')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.code }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('terminal.name')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('public.category')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.category_name }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('public.itoc')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.itoc_name }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('supplier.name')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.supplier_name }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('region.address')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.address }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('terminal.chestNumber')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.chest_number }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('terminal.pathwayNumber')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.track_number }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('public.status')"
          >
            <template slot-scope="scope">
              <span>{{ typeEstimation(scope.row.status) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('public.creationTime')"
          >
            <template slot-scope="scope">
              <span>{{ scope.row.create_time }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            show-overflow-tooltip
            :label="$t('public.creationTime')"
          >
            <template slot-scope="scope">
              <button
                class="operat-buttons"
                @click="cargoLane(scope.row.id)"
              >
                货道管理
              </button>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            :label="$t('table.actions')"
            fixed="right"
          >
            <template slot-scope="scope">
              <div class="operat-button">
                <div
                  class="read-img"
                  @click="handleRead(scope.row)"
                >
                  <img src="@/assets/images/read@2x.png" />
                </div>
                <div
                  class="read-img"
                  @click="handleModifyStatus(scope.row, 'deleted')"
                >
                  <img src="@/assets/images/delete@2x.png" />
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pagination-container">
        <el-pagination
          background
          :current-page="listQuery.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        ></el-pagination>
      </div>
      <!-- 编辑 -->
      <el-dialog
        :title="textMap[dialogStatus]"
        :visible.sync="dialogFormVisible"
      >
        <el-form
          ref="dataForm"
          :rules="rules"
          :model="temp"
          label-position="right"
          label-width="35%"
          style="width: 400px margin-left:120px"
          size="small"
        >
          <div class="pops">
            <div class="information-title">
              <span class="icon-title"></span>
              <span>基础信息:</span>
            </div>
            <div class="pops-item">
              <div class="pops-left">
                <el-form-item
                  :label="$t('terminal.alias') + ' :'"
                  prop="alias"
                >
                  <el-input-number
                    class="left-number"
                    v-model="temp.alias"
                    :controls="false"
                    :disabled="dialogStatus === 'read' ? true : false"
                  ></el-input-number>
                </el-form-item>
                <el-form-item
                  :label="$t('terminal.sn') + ' :'"
                  prop="code"
                >
                  <el-input
                    v-model="temp.code"
                    :readonly="dialogStatus !== 'create' ? true : false"
                  ></el-input>
                </el-form-item>
                <el-form-item
                  :label="$t('terminal.name') + ' :'"
                  prop="name"
                >
                  <el-input
                    v-model="temp.name"
                    :readonly="dialogStatus === 'read' ? true : false"
                  ></el-input>
                </el-form-item>
                <el-form-item
                  :label="$t('sort.name') + ' :'"
                  prop="category_name"
                >
                  <el-input
                    v-model="temp.category_name"
                    :readonly="true"
                  ></el-input>
                </el-form-item>
              </div>
              <div class="pops-right">
                <el-form-item
                  :label="$t('public.itoc') + ' :'"
                  prop="itoc_id"
                >
                  <drop-down-select
                    :data="itocOptions"
                    :count="itocCount"
                    :page-size="pageSize"
                    :id="temp.itoc_id"
                    :name="temp.itoc_name"
                    :disabled="dialogStatus !== 'create' ? true : false"
                    @getList="
                      (pageNumber, search) => {
                        return getItoc(pageNumber, search, 'getItoc');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getItoc(pageNumber, search, 'addItoc');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'itoc');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'itoc');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
                <el-form-item
                  :label="$t('supplier.name') + ' :'"
                  prop="supplier_id"
                >
                  <drop-down-select
                    :data="supplierOptions"
                    :count="supplierCount"
                    :page-size="pageSize"
                    :id="temp.supplier_id"
                    :name="temp.supplier_name"
                    :disabled="dialogStatus === 'read' ? true : false"
                    @getList="
                      (pageNumber, search) => {
                        return getSupplier(pageNumber, search, 'getSupplier');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getSupplier(pageNumber, search, 'addSupplier');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'supplier');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'supplier');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
                <el-form-item
                  :label="$t('region.address') + ' :'"
                  prop="address"
                >
                  <el-input
                    v-model="temp.address"
                    :readonly="dialogStatus === 'read' ? true : false"
                  ></el-input>
                </el-form-item>
                <el-form-item :label="$t('terminal.chestNumber') + ' :'">
                  <el-input-number
                    class="left-number"
                    v-model="temp.chest_number"
                    :controls="false"
                    :min="1"
                    :max="9"
                    :disabled="dialogStatus === 'read' ? true : false"
                  ></el-input-number>
                </el-form-item>
                <el-form-item
                  v-if="dialogStatus !== 'create'"
                  :label="$t('terminal.pathwayNumber') + ' :'"
                >
                  <el-input-number
                    class="left-number"
                    v-model="temp.track_number"
                    :controls="false"
                    :disabled="true"
                  ></el-input-number>
                </el-form-item>
              </div>
            </div>
            <div class="information-title">
              <span class="icon-title"></span>
              <span>其他信息:</span>
            </div>
            <div class="pops-item">
              <div class="pops-left">
                <el-form-item
                  :label="$t('public.investors') + ' :'"
                  prop="invest_name"
                >
                  <drop-down-select
                    :data="investOptions"
                    :count="investCount"
                    :page-size="pageSize"
                    :disabled="dialogStatus === 'read' ? true : false"
                    :id="temp.invest_id"
                    :name="temp.invest_name"
                    @getList="
                      (pageNumber, search) => {
                        return getInvest(pageNumber, search, 'getInvest');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getInvest(pageNumber, search, 'addInvest');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'invest');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'invest');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
                <el-form-item
                  :label="$t('business.name') + ' :'"
                  prop="merchant_name"
                >
                  <drop-down-select
                    :data="merchantOptions"
                    :count="merchantCount"
                    :page-size="pageSize"
                    :disabled="dialogStatus === 'read' ? true : false"
                    :id="temp.merchant_id"
                    :name="temp.merchant_name"
                    @getList="
                      (pageNumber, search) => {
                        return getMerchant(pageNumber, search, 'getMerchant');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getMerchant(pageNumber, search, 'addMerchant');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'merchant');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'merchant');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
              </div>
              <div class="pops-right">
                <el-form-item
                  :label="$t('partner.name') + ' :'"
                  prop="partner_name"
                >
                  <drop-down-select
                    :data="partnerOptions"
                    :count="partnerCount"
                    :page-size="pageSize"
                    :disabled="dialogStatus === 'read' ? true : false"
                    :id="temp.partner_id"
                    :name="temp.partner_name"
                    @getList="
                      (pageNumber, search) => {
                        return getPartner(pageNumber, search, 'getPartner');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getPartner(pageNumber, search, 'addPartner');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'partner');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'partner');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
                <el-form-item
                  :label="$t('maintain.name') + ' :'"
                  prop="maintain_name"
                >
                  <drop-down-select
                    :data="maintainOptions"
                    :count="maintainCount"
                    :page-size="pageSize"
                    :disabled="dialogStatus === 'read' ? true : false"
                    :id="temp.maintain_id"
                    :name="temp.maintain_name"
                    @getList="
                      (pageNumber, search) => {
                        return getMaintain(pageNumber, search, 'getMaintain');
                      }
                    "
                    @addList="
                      (pageNumber, search) => {
                        return getMaintain(pageNumber, search, 'addMaintain');
                      }
                    "
                    @choose="
                      data => {
                        return choose(data, 'maintain');
                      }
                    "
                    @remove="
                      data => {
                        return remove(data, 'maintain');
                      }
                    "
                  ></drop-down-select>
                </el-form-item>
              </div>
            </div>
          </div>
        </el-form>
        <div
          slot="footer"
          class="dialog-footer between-space"
        >
          <div>
            <el-button
              v-show="dialogStatus == 'read'"
              type="primary"
              @click="handleEdit"
            >{{ $t("table.edit") }}</el-button>
          </div>
          <div>
            <el-button @click="dialogFormVisible = false">{{
              $t("table.cancel")
            }}</el-button>
            <el-button
              v-if="dialogStatus == 'create'"
              type="primary"
              :disabled="!createDisabled"
              @click="createData"
            >{{ $t("table.confirm") }}</el-button>
            <el-button
              v-else-if="dialogStatus == 'edit'"
              type="primary"
              :disabled="!updateDisabled"
              @click="updateData"
            >{{ $t("table.confirm") }}</el-button>
            <el-button
              v-else
              type="primary"
              @click="dialogFormVisible = false"
            >{{ $t("table.confirm") }}</el-button>
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script type="text/javascript">
import dropDownSelect from "@/views/select/dropDownSelect"; // 分页选择控件
import { getToken } from "@/utils/auth";
export default {
  name: "TerminalList",
  components: {
    "drop-down-select": dropDownSelect
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        category_name: "",
        partner_name: "",
        merchant_name: "",
        invest_name: ""
      },
      temp: {
        id: undefined,
        alias: undefined,
        code: "",
        name: "",
        category_name: "午餐机",
        itoc_id: undefined,
        itoc_name: "",
        address: "",
        chest_number: undefined,
        invest_id: undefined,
        invest_name: "",
        merchant_id: undefined,
        merchant_name: "",
        partner_id: undefined,
        partner_name: "",
        maintain_id: undefined,
        maintain_name: "",
        supplier_id: undefined,
        supplier_name: ""
      },
      dialogFormVisible: false,
      dialogStatus: "",
      textMap: {
        edit: "编辑",
        create: "添加",
        review: "审核",
        read: "查看"
      },
      rules: {
        code: [{ required: true, message: "请填写SN号", trigger: "blur" }],
        name: [{ required: true, message: "请填写设备名称", trigger: "blur" }],
        address: [
          { required: true, message: "请填写详细地址", trigger: "blur" }
        ],
        itoc_id: [
          { required: true, message: "请选择运营中心", trigger: "change" }
        ],
        supplier_id: [
          { required: true, message: "请选择供应商", trigger: "change" }
        ]
      },
      createDisabled: true,
      updateDisabled: true,
      circleOptions: undefined,
      circleCount: undefined,
      maintainOptions: [],
      maintainCount: undefined,
      itocOptions: [],
      itocCount: undefined,
      investOptions: [],
      investCount: undefined,
      merchantOptions: [],
      merchantCount: undefined,
      partnerOptions: [],
      partnerCount: undefined,
      supplierOptions: [],
      supplierCount: undefined,
      pageSize: 20,
      optionProps: {
        value: "id",
        label: "name"
      }
    };
  },
  created() {
    const token = getToken();
    if (
      token &&
      !this.$store.state.socket.loginTransition &&
      !this.$store.state.socket.loginAccount
    ) {
      this.tokenLogin(token);
    }
    this.getList();
  },
  methods: {
    tokenLogin(token) {
      const path = {
        app: "wxadmin",
        api: "api_wxadmin_admin_keepLogin",
        version: "1.0",
        type: 2,
        data: {
          token: token
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        this.socketData(res);
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
    handleRefresh() {
      this.listQuery = {
        page: 1,
        limit: 20,
        category_name: "",
        partner_name: "",
        merchant_name: "",
        invest_name: ""
      };
      this.getList();
    },
    // 获取终端列表
    getList() {
      this.listLoading = true;
      const data = {
        rows: this.listQuery.limit,
        page: this.listQuery.page,
        alias: this.listQuery.alias ? this.listQuery.alias : "",
        code: this.listQuery.code ? this.listQuery.code : "",
        name: this.listQuery.name ? this.listQuery.name : ""
      };
      const path = {
        app: "archives",
        api: "api_equipment_index_getList",
        version: "1.0",
        data: data
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    handleRead(row) {
      // 打开查看弹窗
      this.temp = Object.assign({}, row); // copy obj
      this.dialogStatus = "read";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleCreate() {
      this.resetTemp();
      this.dialogStatus = "create";
      this.dialogFormVisible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    handleEdit() {
      this.dialogStatus = "edit";
      this.$nextTick(() => {
        this.$refs["dataForm"].clearValidate();
      });
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        alias: undefined,
        code: "",
        name: "",
        category_name: "午餐机",
        itoc_id: undefined,
        itoc_name: "",
        address: "",
        chest_number: undefined,
        invest_id: undefined,
        invest_name: "",
        merchant_id: undefined,
        merchant_name: "",
        partner_id: undefined,
        partner_name: "",
        maintain_id: undefined,
        maintain_name: "",
        supplier_id: undefined,
        supplier_name: ""
      };
    },
    // 更新数据
    upData() {
      const data = {
        id: this.temp.id ? this.temp.id : "",
        alias: this.temp.alias ? this.temp.alias : "",
        code: this.temp.code ? this.temp.code : "",
        name: this.temp.name ? this.temp.name : "",
        category_name: "午餐机",
        itoc_id: this.temp.itoc_id ? this.temp.itoc_id : "",
        itoc_name: this.temp.itoc_name ? this.temp.itoc_name : "",
        address: this.temp.address ? this.temp.address : "",
        chest_number: this.temp.chest_number ? this.temp.chest_number : "",
        invest_id: this.temp.invest_id ? this.temp.invest_id : "",
        invest_name: this.temp.invest_name ? this.temp.invest_name : "",
        merchant_id: this.temp.merchant_id ? this.temp.merchant_id : "",
        merchant_name: this.temp.merchant_name ? this.temp.merchant_name : "",
        partner_id: this.temp.partner_id ? this.temp.partner_id : "",
        partner_name: this.temp.partner_name ? this.temp.partner_name : "",
        maintain_id: this.temp.maintain_id ? this.temp.maintain_id : "",
        maintain_name: this.temp.maintain_name ? this.temp.maintain_name : "",
        supplier_id: this.temp.supplier_id ? this.temp.supplier_id : "",
        supplier_name: this.temp.supplier_name ? this.temp.supplier_name : ""
      };
      return data;
    },
    // 新建终端档案
    createData() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.updateDisabled) {
            this.updateDisabled = false;
            const data = this.upData();
            const path = {
              app: "equipment",
              api: "api_equipment_index_addEquipment",
              version: "1.0",
              type: 2,
              data: data
            };
            this.socketApi.sendSock(JSON.stringify(path), res => {
              if (res) {
                this.socketData(res);
              }
              setTimeout(() => {
                this.updateDisabled = true;
              }, 1000);
            });
          }
        }
      });
    },
    // 更新终端档案
    updateData() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          if (this.updateDisabled) {
            this.updateDisabled = false;
            const data = this.upData();
            const path = {
              app: "equipment",
              api: "api_equipment_index_edit",
              version: "1.0",
              type: 2,
              data: data
            };
            this.socketApi.sendSock(JSON.stringify(path), res => {
              if (res) {
                this.socketData(res);
              }
              setTimeout(() => {
                this.updateDisabled = true;
              }, 1000);
            });
          }
        }
      });
    },
    handleModifyStatus(row) {
      this.$confirm("此操作将永久删除该终端信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const path = {
            app: "equipment",
            api: "api_equipment_index_delete",
            version: "1.0",
            data: {
              id: row.id
            }
          };
          this.socketApi.sendSock(JSON.stringify(path), res => {
            if (res) {
              this.socketData(res);
            } else {
              this.$message.error(" 删除失败 ");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 商圈选择
    getCircle(pageNumber, search, name) {
      const path = {
        app: "common",
        api: "api_archives_merchantCircle_getList",
        version: "1.0",
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 获取供应商
    getSupplier(pageNumber, search, name) {
      const path = {
        app: "archives",
        api: "api_archives_supplier_getList",
        version: "1.0",
        type: 2,
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      console.log("JSON.stringify(path)", JSON.stringify(path));
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 维护人
    getMaintain(pageNumber, search, name) {
      const path = {
        app: "archives",
        api: "api_archives_maintain_getList",
        version: "1.0",
        type: 2,
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 运营中心选择
    getItoc(pageNumber, search, name) {
      const path = {
        app: "archives",
        api: "api_archives_itoc_itocList",
        version: "1.0",
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 投资人选择
    getInvest(pageNumber, search, name) {
      const path = {
        app: "archives",
        api: "api_archives_invest_getList",
        version: "1.0",
        type: 2,
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 合伙人选择
    getPartner(pageNumber, search, name) {
      const path = {
        app: "archives",
        api: "api_archives_partner_getList",
        version: "1.0",
        type: 2,
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || ""
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    // 商家选择
    getMerchant(pageNumber, search, name) {
      const path = {
        app: "common",
        api: "api_archives_merchant_getList",
        version: "1.0",
        data: {
          rows: this.pageSize,
          page: pageNumber || 1,
          name: search || "",
          returnType: name || "",
          type: 2
        }
      };
      this.socketApi.sendSock(JSON.stringify(path), res => {
        if (res) {
          this.socketData(res);
        }
      });
    },
    choose(data, name) {
      if (name === "itoc") {
        this.temp.itoc_id = data.id;
        this.temp.itoc_name = data.name;
      } else if (name === "maintain") {
        this.temp.maintain_id = data.id;
        this.temp.maintain_name = data.name;
      } else if (name === "invest") {
        this.temp.invest_id = data.id;
        this.temp.invest_name = data.name;
      } else if (name === "partner") {
        this.temp.partner_id = data.id;
        this.temp.partner_name = data.name;
      } else if (name === "merchant") {
        this.temp.merchant_id = data.id;
        this.temp.merchant_name = data.name;
      } else if (name === "supplier") {
        this.temp.supplier_id = data.id;
        this.temp.supplier_name = data.name;
      }
    },
    remove(data, name) {
      if (name === "itoc") {
        this.temp.itoc_id = undefined;
        this.temp.itoc_namee = "";
      } else if (name === "maintain") {
        this.temp.maintain_id = undefined;
        this.temp.maintain_name = "";
      } else if (name === "invest") {
        this.temp.invest_id = undefined;
        this.temp.invest_name = "";
      } else if (name === "partner") {
        this.temp.partner_id = undefined;
        this.temp.partner_name = "";
      } else if (name === "merchant") {
        this.temp.merchant_id = undefined;
        this.temp.merchant_name = "";
      } else if (name === "supplier") {
        this.temp.supplier_id = undefined;
        this.temp.supplier_name = "";
      }
    },
    socketData(res) {
      if (res !== '{"type":"ping"}') {
        const resj = JSON.parse(res);
        if (resj.code === -1) {
          this.$message.error(resj.message);
        } else {
          if (resj.api === "api_wxadmin_admin_keepLogin") {
            this.$store.dispatch("loginTransition", true);
            this.socketApi.sendCache(res => {
              this.socketData(res);
            });
          } else if (resj.api === "api_equipment_index_getList") {
            this.total = resj.count;
            this.list = resj.data;
            this.listLoading = false;
            console.log("this.list", this.list);
          } else if (resj.api === "api_equipment_index_addEquipment") {
            this.$notify({
              title: "成功",
              message: "添加成功",
              type: "success",
              duration: 2000
            });
            this.dialogFormVisible = false;
            this.getList();
          } else if (resj.api === "api_equipment_index_edit") {
            this.$notify({
              title: "成功",
              message: "更新成功",
              type: "success",
              duration: 2000
            });
            this.dialogFormVisible = false;
            this.getList();
          } else if (resj.api === "api_equipment_index_delete") {
            this.$notify({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000
            });
            this.dialogFormVisible = false;
            this.getList();
          } else if (
            resj.api === "api_archives_maintain_getList" &&
            resj.type === "getMaintain"
          ) {
            this.maintainOptions = resj.data;
            this.maintainCount = resj.count;
          } else if (
            resj.api === "api_archives_maintain_getList" &&
            resj.type === "addMaintain"
          ) {
            this.maintainOptions = this.maintainOptions.concat(resj.data);
          } else if (
            resj.api === "api_archives_itoc_itocList" &&
            resj.type === "getItoc"
          ) {
            this.itocOptions = resj.data;
            this.itocCount = resj.count;
          } else if (
            resj.api === "api_archives_itoc_itocList" &&
            resj.type === "addItoc"
          ) {
            this.itocOptions = this.itocOptions.concat(resj.data);
          } else if (
            resj.api === "api_archives_invest_getList" &&
            resj.type === "getInvest"
          ) {
            this.investOptions = resj.data;
            this.investCount = resj.count;
          } else if (
            resj.api === "api_archives_invest_getList" &&
            resj.type === "addInvest"
          ) {
            this.investOptions = this.investOptions.concat(resj.data);
          } else if (
            resj.api === "api_archives_partner_getList" &&
            resj.type === "getPartner"
          ) {
            this.partnerOptions = resj.data;
            this.partnerCount = resj.count;
          } else if (
            resj.api === "api_archives_partner_getList" &&
            resj.type === "addPartner"
          ) {
            this.partnerOptions = this.partnerOptions.concat(resj.data);
          } else if (
            resj.api === "api_archives_merchant_getList" &&
            resj.type === "getMerchant"
          ) {
            this.merchantOptions = resj.data;
            this.merchantCount = resj.count;
          } else if (
            resj.api === "api_archives_merchant_getList" &&
            resj.type === "addMerchant"
          ) {
            this.merchantOptions = this.merchantOptions.concat(resj.data);
          } else if (
            resj.api === "api_archives_supplier_getList" &&
            resj.type === "getSupplier"
          ) {
            this.supplierOptions = resj.data;
            this.supplierCount = resj.count;
          } else if (
            resj.api === "api_archives_supplier_getList" &&
            resj.type === "addSupplier"
          ) {
            this.supplierOptions = this.supplierOptions.concat(resj.data);
          }
        }
      }
    },
    cargoLane(id) {
      this.$router.push({
        path: "/terminal-data/cargo-lane-manag",
        query: {
          id: id
        }
      });
    }
  }
};
</script>
<style scoped>
.operat-buttons {
  width: 88px;
  height: 32px;
  background: rgba(228, 234, 248, 1);
  border-radius: 16px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  border: none;
  cursor: pointer;
}
</style>
